#include <cpu.h>
#include <mmu.h>
#include <sysreg.h>
#include <virt.h>
#include <kvm_arm.h>
#include <assembler.h>
#include <gic_v3.h>
#include <linkage.h>

.section ".text.boot"

.global _start

_start:
    mrs x1, mpidr_el1
    and x1, x1, #3
    cbz x1, cpu0_start

secondary_cpu_deadloop:
    wfe
    b secondary_cpu_deadloop


ENTRY(cpu0_start)
	bl	el2_setup			// Drop to EL1, w0=cpu_boot_mode
	b	__primary_switch
ENDPROC(cpu0_start)

__primary_switch:
    /* about to jump main */
    ldr x1, =stack_begin
    //msr sp_el1, x1

    mov sp, x1

    /* clear bss section */
    ldr x1, =__bss_start
    ldr w2, =__bss_size
bss_clear:
    cbz w2, c_entry
    str xzr, [x1], #8
    sub w2, w2, #1
    cbnz w2, bss_clear

c_entry:
    bl main

deadloop:
    b deadloop
